Imports System.Windows.Forms
Imports TeamUp.Fachada
Imports TeamUp.Entidades

Public Class frmListaProjetos
    Private lstProjeto As List(Of Projeto)
    Private objUsuarioLogado As Usuario
    Private strIdProjeto As String
    Private objMdiPrincipal As frmMdiSEP

    Public Sub setMdi(ByVal objMdi As frmMdiSEP)
        objMdiPrincipal = objMdi
    End Sub

    Public Function getIdProjeto() As String
        getIdProjeto = strIdProjeto
    End Function


    Public Property UsuarioLogado() As Usuario
        Get
            Return Me.objUsuarioLogado
        End Get
        Set(ByVal Value As Usuario)
            Me.objUsuarioLogado = Value
        End Set
    End Property

    Public Sub carregarGridProjeto()
        Dim objFachada As Facade

        Dim intContador As Integer = 0
        Try
            objFachada = Facade.getInstance()
            lstProjeto = objFachada.consultarProjeto("")

            If Not lstProjeto Is Nothing Then
                grdProjeto.DataSource = lstProjeto
            End If

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "SEP")
        End Try
    End Sub

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        strIdProjeto = grdProjeto.Item("id", grdProjeto.CurrentRow.Index).Value
        If getIdProjeto() <> "" Then
            objMdiPrincipal.setCodigoProjeto(getIdProjeto)
            objMdiPrincipal.carregarListProjeto(getIdProjeto)
            objMdiPrincipal.carregarTreeView()
            If objMdiPrincipal.ExpandirToolStripMenuItem.Checked Then
                objMdiPrincipal.trvProjeto.ExpandAll()
            End If
        End If

        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub frmListaProjetos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        carregarGridProjeto()
    End Sub
End Class
